package com.example.pulsar.controller;

import com.example.pulsar.service.ProducerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.client.api.PulsarClientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: 141040
 * @Date: 3/25/2019 10:20
 * @Description:
 */
@Api(tags = "Pulsar生产者控制器", description = "Pulsar生产者控制器")
@RestController
public class ProducerController {

    @Autowired
    private ProducerService producerService;

    @ApiOperation(value = "Pulsar生产者请求方法", notes = "Pulsar生产者请求方法")
    @GetMapping(value = "/createProducer")
    public String createProducer() {
        String message;
        try {
            MessageId messageId = producerService.createProducer();
            message = "Pulsar信息发送成功,返回messageId为：" + messageId;
        } catch (PulsarClientException e) {
            message = "Pulsar信息发送异常,信息如:" + e.getMessage();
        }
        return message;
    }

}
